﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutList.cshtml";
}
<style type="text/css">
    .div-collapse {
        float: left;
        height: 20px;
        line-height: 20px;
        padding-left: 5px;
    }
</style>
<!--模糊搜索区域-->
<div class="layui-row">
    <form class="layui-form layui-col-md12 ok-search">
        <div class="layui-input-inline">
            <input class="layui-input" placeholder="请输入井位编码" id="EnCode" name="EnCode" autocomplete="off">
        </div>
        <div class="layui-input-inline">
            <input class="layui-input" placeholder="请输入井位名称"  id="WellName" name="WellName" autocomplete="off">
        </div>
        <div class="layui-input-inline">
            <!-- treeSelect渲染会给input自动加上style="display: none;"，导致jquery无法给input赋值，type text要改为hidden，但会存在渲染的过程 -->
            <input type="hidden" id="OrganizeId" name="OrganizeId" autocomplete="off" class="layui-input">
        </div>
        @Html.SearchBtnHtml("查询")
        @Html.ResetBtnHtml()
    </form>
</div>
<!--数据表格-->
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
<script>
    layui.use(["form","table", "okLayer", "okUtils", "treeSelect"], function () {
        let table = layui.table;
        let form = layui.form;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        let treeSelect = layui.treeSelect;
        let $ = layui.$;
        treeSelect.render({
            elem: "#OrganizeId",
            data: "/Permissions/Well/GetOrganizeTreeSelect",
            type: "GET"
        });

        let AllTable = table.render({
            elem: "#tableId",
            url: "/Permissions/Well/List",
            limit: 100,
            page: true,
            toolbar: "#toolbarTpl",
            size: "sm",
            cols: [[
                { type: "checkbox" },
                { field: "Id", title: "ID", width: 60, sort: true },
                { field: "WellName", title: "井号", width: 80 },
                { field: "WellType", title: "井类型", width: 80 },
                { field: "IO_ServerID", title: "采集站", width: 120 },
                { field: "IO_CommunicateID", title: "通道", width: 120 },
                { field: "IO_DeviceID", title: "设备ID", width: 120 },
                { field: "Contractor", title: "承包商", width: 120 },
                { field: "CreateTime", title: "创建时间", width: 150, templet: '<span>{{showDate(d.CreateTime)}}<span>' },
                { title: "操作", width: 180, align: "center", fixed: "right", templet: "#operationTpl" }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        
        form.on("submit(search)", function (data) {
            AllTable.reload({
                where: data.field,
                page: { curr: 1 }
            });
            return false;
        });
        //add
        $('#add').on('click', function () {
            okLayer.open("添加井位", "/Permissions/Well/Add", "100%", "100%", null, null);
        });


        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "edit":
                    edit(data.Id);//field Id 和 数据库表字段 Id 要一致
                    break;
                case "del":
                    del(data.Id);
                    break;
                case "browser":
                    browser(data.Id);
                    break;
            }
        });

        function add() {
            okLayer.open("添加井位", "/Permissions/Well/Add", "100%", "100%", null, null);
        }

        function edit(id) {
            okLayer.open("编辑井位", "/Permissions/Well/Edit/" + id, "100%", "100%", null, null);
        }
        function browser(id) {
            okLayer.open("查看井位信息", "/Permissions/Well/Browser/" + id, "100%", "100%", null, null);
        }
        function del(id) {
            okLayer.confirm("确定要删除吗？", function () {
                okUtils.ajax("/Permissions/Well/Delete", "get", { id: id }, true).done(function (response) {
                    okUtils.tableSuccessMsg(response.message);
                    //没开启分页，没确定按钮，手动刷新
                    setTimeout(function () {
                        window.location.reload();
                    }, 1500);
                }).fail(function (error) {
                    console.log(error)
                });
            })
        }

    })
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
    @Html.TopToolBarHtml(ViewData["TopButtonList"])
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    @Html.RightToolBarHtml(ViewData["RightButtonList"])
</script>

